package org.check.loadProperties;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.check.Util.OrderedProperties;

public class LoadProperty {   
    public static OrderedProperties loadProp() {   
    	OrderedProperties prop = new OrderedProperties(); 
        InputStreamReader inbase = null;
        InputStreamReader inname = null;
		try {
			String path = System.getProperty("user.dir")+"/config/name2attr.properties";
			File file = new File(path);
			inname = new InputStreamReader(new FileInputStream(file),"UTF-8");
			String path1 = System.getProperty("user.dir")+"/config/base2attr.properties";
			File file1 = new File(path1);
			inbase = new InputStreamReader(new FileInputStream(file1),"UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
        try {   
        	prop.load(inname); 
        	prop.load(inbase);
        } catch (IOException e) {   
            e.printStackTrace();   
        }   
       
		return prop;
    } 
    
    public static Properties loadBaseProp() {  
          Properties propbase = new Properties(); 
          InputStreamReader inbase = null;
  		try {
  			String path = System.getProperty("user.dir")+"/config/base2attr.properties";
  			File file = new File(path);
  			inbase = new InputStreamReader(new FileInputStream(file),"UTF-8");
  		} catch (UnsupportedEncodingException e1) {
  			// TODO Auto-generated catch block
  			e1.printStackTrace();
  		} catch (FileNotFoundException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		}   
          try {   
          	propbase.load(inbase);
          } catch (IOException e) {   
              e.printStackTrace();   
          }   
          
  		return propbase;
    }
    
    public static Properties loadNameProp() {  
    	Properties propname = new Properties(); 
        InputStreamReader inname = null;
		try {
			String path = System.getProperty("user.dir")+"/config/name2attr.properties";
			File file = new File(path);
			inname = new InputStreamReader(new FileInputStream(file),"UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
        try {   
        	propname.load(inname); 
        } catch (IOException e) {   
            e.printStackTrace();   
        }   
		return propname;
  }
    
    public static Properties loadCourseTypoProp() {   
        Properties prop = new Properties();   
        InputStreamReader in = null;
		try {
			String path = System.getProperty("user.dir")+"/config/course_Type.properties";
			File file = new File(path);
			in = new InputStreamReader(new FileInputStream(file),"UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
        try {   
            prop.load(in);   
        } catch (IOException e) {   
            e.printStackTrace();   
        }   
        
		return prop;
    } 
    
    public static Properties loadConnProp(String type) {   
        Properties prop = new Properties();   
        InputStreamReader in = null;
		try {
			String path = System.getProperty("user.dir")+"/config/"+type+"connection.properties";
			File file = new File(path);
			in = new InputStreamReader(new FileInputStream(file),"UTF-8");
			} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}   
        try {   
            prop.load(in);   
        } catch (IOException e) {   
            e.printStackTrace();   
        }   
        
		return prop;
    }
  
   
  
    public static void main(String args[]){   
    	Properties prop = loadProp(); 
    	 
    	Iterator it=prop.entrySet().iterator();
 		List<String> tmpList = new LinkedList<String>();
 		while(it.hasNext()){
 		    Map.Entry entry=(Map.Entry)it.next();
 		    Object key = entry.getKey();
 		    Object value = entry.getValue();
 		    System.out.println(key.toString());
 		    System.out.println(value.toString());
 		    String tableName = value.toString();
 		    tmpList.add(tableName);
 		}
    }   
	
}
